produce userdata for VSCode to consume#40
produce userdata for VSCode to consume#40Eskibear merged 9 commits intomicrosoft:masterfrom Eskibear:yanzh_tele
Conversation
|
@Eskibear, |
|
Moreover, I need an AI key for VSCode to send user data. @akaroml |
| public class ProtocolServer { | ||
| private static final Logger logger = Logger.getLogger(Configuration.LOGGER_NAME); | ||
|
|
||
| private static final Logger loggerUserdata = Logger.getLogger(Configuration.USERDATA_LOGGER_NAME); |
There was a problem hiding this comment.
Naming: userDataLogger to make it consistent and readable
|
|
||
| private IDebugAdapter debugAdapter; | ||
|
|
||
| /* userdataMap Schema: |
There was a problem hiding this comment.
Use javadoc style comments
| for (byte b : hashBytes) { | ||
| buf.append(Integer.toHexString((b & 0xFF) + 0x100).substring(1)); | ||
| } | ||
| filenameHash = buf.toString(); |
There was a problem hiding this comment.
Move out the hash function to adapterutils
|
|
||
| if (!response.success || respondingTime > RESPONSE_MAX_DELAY_MS) { | ||
| Map<String, Object> props = new HashMap<>(); | ||
| props.put("respondingTime", respondingTime); |
| if (!response.success || respondingTime > RESPONSE_MAX_DELAY_MS) { | ||
| Map<String, Object> props = new HashMap<>(); | ||
| props.put("respondingTime", respondingTime); | ||
| props.put("requestCommand", requestCommand); |
| if (th != null) { | ||
| errorEntry.put("message", th.getMessage()); | ||
| StringWriter sw = new StringWriter(); | ||
| th.printStackTrace(new PrintWriter(sw)); |
There was a problem hiding this comment.
better to close StringWriter PrintWriter
|
|
||
| // bp count | ||
| if ("setBreakpoints".equals(request.command)) { | ||
| String filename = request.arguments.get("source").getAsJsonObject().get("path").getAsString(); |
There was a problem hiding this comment.
path could be null. need cover this case.
There was a problem hiding this comment.
could use JsonUtils.fromJson(request.arguments, SetBreakpointArguments.class) to get SetBreakpointArguments object.
|
|
||
| props.put("sessionStartAt", String.valueOf(startAt)); | ||
| props.put("sessionStopAt", String.valueOf(stopAt)); | ||
| props.put("commandCount", new Gson().toJson(commandCountMap)); |
There was a problem hiding this comment.
Use JsonUtils.toJson() method instead of new Gson().
|
|
||
| public class JavaDebuggerServerPlugin implements BundleActivator { | ||
| private static final Logger logger = Logger.getLogger(Configuration.LOGGER_NAME); | ||
| private static final Logger loggerUserdata = Logger.getLogger(Configuration.USAGE_DATA_LOGGER_NAME); |
There was a problem hiding this comment.
rename to usageDataLogger
| * @return List of user data Object. | ||
| */ | ||
| public List<Object> fetchAll() { | ||
| List<Object> ret = new ArrayList<>(); |
There was a problem hiding this comment.
Because the result always is parsed to an array on vscode js side, Let fetchAll() return queue.toArray() directly instead of a list.
| // bp count | ||
| if ("setBreakpoints".equals(request.command)) { | ||
| String fileIdentifier = "unknown file"; | ||
| JsonElement pathElement = request.arguments.get("source").getAsJsonObject().get("path"); |
There was a problem hiding this comment.
request.arguments.get("source").getAsJsonObject().get("path"); [](start = 38, length = 62)
could it possibly raise NullPointerException?
There was a problem hiding this comment.
source is supposed not to be null in setBreakpoints, shall we still double check it, or just assume it as NotNull?
| public void stop() { | ||
| usageDataSession.reportStop(); | ||
| this.terminateSession = true; | ||
| usageDataSession.submitUsageData(); |
There was a problem hiding this comment.
i'm not sure, but could it possibly be wrapped in sth like a finally block? namely should we report when exception thrown during the session?
|
a little bit confused, so now if I would like to log something, i should manually specify which logger i'm using? |
|
|
||
| public class Configuration { | ||
| public static final String LOGGER_NAME = "java-debug"; | ||
| public static final String USERDATA_LOGGER_NAME = "java-debug-userdata"; |
|
|
||
| public class Configuration { | ||
| public static final String LOGGER_NAME = "java-debug"; | ||
| public static final String USERDATA_LOGGER_NAME = "java-debug-userdata"; |
| public class ProtocolServer { | ||
| private static final Logger logger = Logger.getLogger(Configuration.LOGGER_NAME); | ||
|
|
||
| private static final Logger loggerUserdata = Logger.getLogger(Configuration.USERDATA_LOGGER_NAME); |
|
|
||
| /* userdataMap Schema: | ||
| * command: { timestamp: Request JSON String } */ | ||
| private Map<String, Map<Long, String>> userdataMap = new HashMap<>(); |
| private Map<String, Map<Long, String>> userdataMap = new HashMap<>(); | ||
|
|
||
| private void recordRequest(Request message) { | ||
| userdataMap.putIfAbsent(message.command, new HashMap<Long, String>()); |
There was a problem hiding this comment.
Why not just save the return value and use it in the next line instead of getting it.
|
|
||
| public class JavaDebugDelegateCommandHandler implements IDelegateCommandHandler { | ||
|
|
||
| public static String FETCH_USER_DATA = "vscode.java.fetchUserData"; |
There was a problem hiding this comment.
FETCH_USER_DATA -> FETCH_USAGE_DATA
vscode.java.fetchUserData -> vscode.java.fetchUsageData
| <command id="vscode.java.startDebugSession"/> | ||
| <command id="vscode.java.resolveClasspath"/> | ||
| <command id="vscode.java.buildWorkspace"/> | ||
| <command id="vscode.java.fetchUserData"/> |
| @Override | ||
| public void publish(LogRecord record) { | ||
| if (record.getLevel().intValue() >= thresholdLevel.intValue()) { | ||
| if (record.getThrown() != null) { |
There was a problem hiding this comment.
Does this mean a log record does not contain exception or extra data object at the same time?
There was a problem hiding this comment.
in Logger, there's no API accepts throwable and extra data at the same time.
| } | ||
|
|
||
| public static UsageDataStore getInstance() { | ||
| return SingletonHolder.INSTANCE; |
There was a problem hiding this comment.
If we have multiple sessions going on at the same time, they will share the same session id, which is not expected.
In VSCode, use following method to get userdata object.